home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / sound / sndplaydoublebuffer / _headers / wave.h < prev   
Encoding:
C/C++ Source or Header  |  2000-06-23  |  5.9 KB  |  223 lines

  1. /*
  2.     File:        WAVE.h
  3.  
  4.     Contains:    Header information needed to parse Microsoft's WAVE formatted sounds.
  5.  
  6.     Written by: Mark Cookson    
  7.  
  8.     Copyright:    Copyright © 1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/31/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24. /* This was made from reading a document called wave.pdf which is an excerpt from
  25.    RIFFMCI.RTF, "Multimedia Programming Interface and Data Specification v1.0".
  26.  
  27.    This code does what I need, and worked with the WAVE files I had handy.
  28.    It may not work in all cases.
  29. */
  30.  
  31. #ifndef __WAVE__
  32. #define __WAVE__
  33.  
  34. #include <Errors.h>
  35. #include <Files.h>
  36. #include <Sound.h>
  37. #include <Types.h>
  38.  
  39. #ifndef __SOUNDSTRUCT__
  40. #include "SoundStruct.h"
  41. #endif
  42.  
  43. #ifndef __DBFFERRORS__
  44. #include "DBFF_Errors.h"
  45. #endif
  46.  
  47. #ifndef __SETUPDBHEADER__
  48. #include "SetupDBHeader.h"
  49. #endif
  50.  
  51. #ifndef __DEFINES__
  52. #include "Defines.h"
  53. #endif
  54.  
  55. #define kWAVEFORMID                (1<<0)
  56. #define kWAVEID                    (1<<1)
  57. #define kFormatID                (1<<2)
  58. #define kWAVEListID                (1<<3)
  59. #define kSilenceID                (1<<4)
  60. #define kCueID                    (1<<5)
  61. #define kFactID                    (1<<6)
  62. #define kPlaylistID                (1<<7)
  63. #define kAssocDataID            (1<<8)
  64. #define kLabelID                (1<<9)
  65. #define kNoteID                    (1<<10)
  66. #define kTextWithLenID            (1<<12)
  67. #define kEmbededFileID            (1<<13)
  68. #define kWAVEDataID                (1<<14)
  69.  
  70. enum {
  71.     WAVEFORMID                    = 'RIFF',
  72.     WAVEID                        = 'WAVE',
  73.     FormatID                    = 'fmt ',
  74.     WAVEListID                    = 'wavl',
  75.     SilenceID                    = 'slnt',
  76.     CueID                        = 'cue ',
  77.     FactID                        = 'fact',
  78.     PlaylistID                    = 'plst',
  79.     AssocDataID                    = 'adtl',
  80.     LabelID                        = 'labl',
  81.     NoteID                        = 'note',
  82.     TextWithLenID                = 'ltxt',
  83.     EmbededFileID                = 'file',
  84.     WAVEDataID                    = 'data'
  85. };
  86.  
  87. #define WAVE_FORMAT_PCM        (0x0001)        /* Microsoft Pulse Code Modulation (PCM) format */
  88. #define WAVE_FORMAT_ADPCM    (0x0002)        /* A WAVE Adaptive Differential Pulse Code Modulation file I saw once */
  89. #define WAVE_FORMAT_MULAW    (0x0007)        /* A WAVE mu-law file that I saw once */
  90. #define WAVE_FORMAT_IMA        (0x0011)        /* A WAVE IMA4 file that I saw once */
  91. #define IBM_FORMAT_MULAW    (0x0101)        /* IBM mu-law format */
  92. #define IBM_FORMAT_ALAW        (0x0102)        /* IBM a-law format */
  93. #define IBM_FORMAT_ADPCM    (0x0103)        /* IBM AVC Adaptive Differential Pulse Code Modulation format */
  94. #define kWAVEChunkBufferSize    128
  95.  
  96. typedef struct WAVEChunkHeader {
  97.     UInt32                ckID;
  98.     long                fileSize;
  99. }WAVEChunkHeader;
  100.  
  101. typedef struct WAVEContainerChunk {
  102.     UInt32                ckID;
  103.     long                ckSize;
  104.     UInt32                formType;
  105. }WAVEContainerChunk;
  106.  
  107. typedef struct fmtChunk {
  108.     UInt32                ckID;
  109.     long                ckSize;
  110.     short                wFormatTag;            /* Number indicating WAVE format category */
  111.     short                wChannels;            /* Number of channels 1 for mono 2 for stereo */
  112.     long                dwSamplesPerSec;    /* Sampling rate in samples per second */
  113.     long                dwAvgBytesPerSec;    /* Average number of bytes per second (could be used to estimate buffer sizes) */
  114.     short                wBlockAlign;        /* Block alignment in bytes of the waveform data, always process an integer multiple of this number */
  115. }fmtChunk;
  116.  
  117. typedef struct PCMFmtSpecChunk {
  118.     UInt32                ckID;
  119.     long                ckSize;
  120.     short                wBitsPerSample;        /* Sample size */
  121. }PCMFmtSpecChunk;
  122.  
  123. typedef struct factChunk {
  124.     UInt32                ckID;
  125.     long                ckSize;
  126.     long                dwFileSize;            /* Number of samples */
  127. }factChunk;
  128.  
  129. typedef struct cuePointsChunk {
  130.     UInt32                ckID;
  131.     long                ckSize;
  132.     long                dwCuePoints;        /* Count of cue points */
  133.     /* There may be multiple number of these */
  134.     long                dwName;
  135.     long                dwPosition;
  136.     long                fccChunk;
  137.     long                dwChunkStart;
  138.     long                dwBlockStart;
  139.     long                dwSampleOffset;
  140. }cuePointsChunk;
  141.  
  142. typedef struct playlistChunk {
  143.     UInt32                ckID;
  144.     long                ckSize;
  145.     long                dwSegments;            /* Count of play segments */
  146.     /* There may be multiple number of these */
  147.     long                dwName;
  148.     long                dwLength;
  149.     long                dwLoops;
  150. }playlistChunk;
  151.  
  152. //typedef struct waveDataChunk {
  153. //    UInt32                ckID;
  154. //    short                something;            /* I don't know what this is */
  155. //}waveDataChunk;
  156.  
  157. typedef struct labelChunk {
  158.     UInt32                ckID;
  159.     long                dwName;
  160.     char                data[1];            /* This is a null terminated string */
  161. }labelChunk;
  162.  
  163. typedef struct noteChunk {
  164.     UInt32                ckID;
  165.     long                ckSize;
  166.     long                dwName;
  167.     char                data[1];            /* This is a null terminated string */
  168. }noteChunk;
  169.  
  170. typedef struct ltxtChunk {
  171.     UInt32                ckID;
  172.     long                ckSize;
  173.     long                dwName;
  174.     long                dwSampleLength;
  175.     long                dwPurpose;
  176.     short                wCountry;
  177.     short                wLanguage;
  178.     short                wDialect;
  179.     short                wCodePage;
  180.     char                data[1];            /* This is a null terminated string */
  181. }ltxtChunk;
  182.  
  183. typedef struct fileChunk {
  184.     UInt32                ckID;
  185.     long                ckSize;
  186.     long                dwName;
  187.     long                dwMedType;
  188.     char                data[1];            /* This is a null terminated string */
  189. }fileChunk;
  190.  
  191. typedef struct assocDataListChunk {
  192.     UInt32                ckID;
  193.     long                ckSize;
  194.     labelChunk            labelInfo;
  195.     noteChunk            noteInfo;
  196.     ltxtChunk            ltxtInfo;
  197.     fileChunk            fileInfo;
  198. }assocDataListChunk;
  199.  
  200. typedef union {
  201.     WAVEChunkHeader            generic;
  202.     WAVEContainerChunk        container;
  203.     fmtChunk                fmt;
  204.     factChunk                fact;
  205.     cuePointsChunk            cuePoints;
  206.     playlistChunk            playList;
  207.     assocDataListChunk        assocData;
  208. //    waveDataChunk            waveData;
  209.     PCMFmtSpecChunk            waveData;
  210. }WAVETemplate, *WAVETemplatePtr;
  211.  
  212. OSErr        ASoundGetWAVEHeader        (SoundInfoPtr theSoundInfo,
  213.                                     long *dataStart,
  214.                                     long *length);
  215.  
  216. short        SwapShort                (const short theShort);
  217. long        SwapLong                (const long theLong);
  218. long        ReverseLong                (const long theLong);
  219.  
  220. #define stillMoreDataWAVEToRead        ((chunkFlags & kWAVEFORMID) && (!(chunkFlags & kFormatID) || !(chunkFlags & kWAVEDataID)) && (err == noErr))
  221.  
  222. #endif
  223.